//
//  TeaacherCheckHolidayViewController.m
//  LoveDraw
//
//  Created by 零零壹 on 2017/8/11.
//  Copyright © 2017年 梁晨. All rights reserved.
//

#import "TeaacherCheckHolidayViewController.h"
#import "TeacherCheckTableViewCell.h"
#import "TeaacherCheckHolidayModel.h"
#import "UILabel+ChangeLineSpaceAndWordSpace.h"
//#import "TeacherCheckHoildayTableViewCell.h"

@interface TeaacherCheckHolidayViewController ()<UITableViewDelegate,UITableViewDataSource>
{
    NSInteger page;
}
@property(nonatomic,strong)UITableView *TableV;
@property(nonatomic,strong)NSMutableArray *listArr;

@end

@implementation TeaacherCheckHolidayViewController

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:NO animated:YES];

}

-(NSMutableArray *)listArr
{
    if (!_listArr) {
        _listArr = [NSMutableArray array];
    }
    return _listArr;
}

-(UITableView *)TableV
{
    if (!_TableV) {
        _TableV = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, KscreenW, KscreenH-64) style:(UITableViewStyleGrouped)];
        _TableV.delegate = self;
        _TableV.dataSource = self;
        _TableV.estimatedSectionHeaderHeight = 0;
        _TableV.estimatedSectionFooterHeight = 0;
        [_TableV registerClass:[TeacherCheckTableViewCell class] forCellReuseIdentifier:@"TeacherCheckTableViewCell"];
        _TableV.separatorStyle = 0;
        _TableV.backgroundColor = [UIColor whiteColor];
    }
    return _TableV;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.view addSubview:self.TableV];
    self.navigationItem.title = @"学生请假记录";
    page = 1;
    
    self.TableV.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
        page++;
        [self Request];
    }];
    self.TableV.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        [self doRefreshSenior];
    }];

    [self.TableV.mj_header beginRefreshing];

}
-(void)doRefreshSenior
{
    page = 1;
    [self Request];
}

-(void)Request
{
    [RequestManager RequstWithUrl:@"/index.php?g=App&m=TeacherCourse&a=studentLeavelogs" parmDic:@{@"ctaid":self.ctaid,@"page":@"0"} requestType:RequestGET Success:^(id data)
    {
        NSArray *Arr = [TeaacherCheckHolidayModel modelConfigure:data];
        if (page == 1) {
            [self.listArr removeAllObjects];
        }
        if (Arr.count==0) {
            page--;
        }
        [self.listArr addObjectsFromArray:Arr];
        [self.TableV reloadData];
        [self.TableV.mj_header endRefreshing];
        [self.TableV.mj_footer endRefreshing];

        if (Arr.count == 0||Arr.count<10)
        {
            self.TableV.mj_footer.state = MJRefreshStateNoMoreData;
        }

    } error:^(NSError *error) {

    }];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (self.listArr.count == 0) {
        self.TableV.backgroundView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"nodata"]];
    }else
    {
        self.TableV.backgroundView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@""]];
    }
    return self.listArr.count;
}

// Row display. Implementers should *always* try to reuse cells by setting each cell's reuseIdentifier and querying for available reusable cells with dequeueReusableCellWithIdentifier:
// Cell gets various attributes set automatically based on table (separators) and data source (accessory views, editing controls)

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 80;
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return FLT_MIN;
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return FLT_MIN;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    TeaacherCheckHolidayModel *model = self.listArr[indexPath.row];
    TeacherCheckTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"TeacherCheckTableViewCell" forIndexPath:indexPath];

    [cell.leftYear setText:model.date_year];
    [cell.leftMonth setText:model.date_md];
    [cell.leftImage setImage:[UIImage imageNamed:@"round"]];
    [cell.titleLabel setText:model.coursename];
    [cell.remarkLabel setText:model.detail];
//    [UILabel changeLineSpaceForLabel:cell.remarkLabel WithSpace:5.0];
    if (indexPath.row  == 0) {
        [cell.lineView setHidden:YES];
    }else
    {
        [cell.lineView setHidden:NO];
    }
    cell.selectionStyle = 0;
    return cell;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
